package juc;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 推荐使用 ThreadPoolExecutor
 */
@Deprecated
public class ThreadPoolUtil {
    private static final ScheduledExecutorService DEFAULT_THREAD_POOL = Executors.newScheduledThreadPool(10);

    public static void main(String[] args) {
        ThreadPoolUtil.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("=====业务处理===");
            }
        });
    }

    /**
     * 立即执行
     *
     * @param task
     */
    public static void execute(Runnable task) {
        DEFAULT_THREAD_POOL.execute(task);
    }

    /**
     * 延时指定多少秒后执行
     *
     * @param task
     * @param delaySecond
     */
    public static void executeLater(Runnable task, int delaySecond) {
        DEFAULT_THREAD_POOL.schedule(task, delaySecond, TimeUnit.SECONDS);
    }
}
